package org.jeecg.modules.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.system.vo.MemberModel;
import org.jeecg.config.app.AppContext;
import org.jeecg.modules.api.member.entity.Member;
import org.jeecg.modules.api.member.mapper.MemberMapper;
import org.jeecg.modules.api.member.service.IMemberService;
import org.jeecg.modules.api.order.service.IOrderService;
import org.jeecg.modules.app.service.ITeamService;
import org.jeecg.modules.helper.MemberHelp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 团队接口实现类
 * @author: Young Jun
 * @date: 2024年09月24日 11:42
 */
@Service
@Slf4j
public class TeamServiceImpl implements ITeamService {

    @Autowired
    private IMemberService memberService;
    @Autowired
    private IOrderService orderService;
    @Autowired
    private MemberHelp memberHelp;
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<Member> getMyTeam(Long memberId) {
        if (memberId == null) {
            MemberModel memberModel = AppContext.get();
            memberId = memberModel.getId();
        }
        List<Member> list = memberService.list(new LambdaQueryWrapper<Member>().eq(Member::getRecommendId, memberId));
        for (Member m : list) {
            int number = orderService.getFxOrderNum(m.getId());
            m.setOrderNum(number);
            List<Member> childTeamList = memberService.list(new LambdaQueryWrapper<Member>().eq(Member::getRecommendId, m.getId()));
            for (Member child : childTeamList) {
                int childNumber = orderService.getFxOrderNum(m.getId());
                child.setOrderNum(childNumber);
            }
            m.setChildList(childTeamList);
        }
        return list;
    }

    @Override
    public List<Member> getRankList() {
        //获取前50排名
        List<Member> rankList = memberService.getRankList(50);
        return rankList;
    }
}

